/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ca.trader.utils;

import ca.trader.except.InvalidEmailAddressException;
import ca.trader.except.PasswordLengthException;
import ca.trader.user.User;
import org.apache.commons.validator.EmailValidator;

public class UserValidationUtils
{

	 private static final int MIN_PASSWORD_LENGTH = 6;
	 private static final int MAX_PASSWORD_LENGTH = 15;

	 public static void validateUser(User user, String originalPassword) throws PasswordLengthException, InvalidEmailAddressException
	 {
		  if (originalPassword.length() < MIN_PASSWORD_LENGTH || originalPassword.length() > MAX_PASSWORD_LENGTH)
		  {
			   throw new PasswordLengthException(MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH);
		  }

		  if (!EmailValidator.getInstance().isValid(user.getEmail()))
		  {
			   throw new InvalidEmailAddressException(user.getEmail());
		  }
	 }

}
